home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / jdp1_4.zip / JDP1_4.EXE / data.1 / JDPLayout2.java < prev    next >
Text File  |  1996-10-18  |  13KB  |  469 lines

  1. >XXX0454  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13. import java.util.Date;
  14.  
  15.  
  16. >003public class <JDPUserBill> extends JDPClassLayout {
  17.  
  18.     JDPUser user;
  19.     JDPJagg jaggSQL;
  20.     JDPTextGrid tableContents;
  21.     JDPWhereClause jdpWhereClause;
  22.     JDPPopupMessage popuppanel;
  23.  
  24.     String[] psortChoice;
  25.     String[] pdisplayChoice;
  26.     int itemIndex;
  27.     boolean insertRequested = false;
  28.     boolean deleteRequested = false;
  29.     String pfromWhereClause;
  30.     String[][] rowKey;
  31.     int totalRows;
  32.     int keyCount;
  33.     int prevColumnCount;
  34. >119    int columnCount = <columnCount>;
  35. >052    Vector value<name>;
  36.  
  37.     Vector pmatchUsing;
  38.     Vector pactualmatchUsing;
  39.  
  40.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  41.  
  42.         this.user = user;
  43.         //
  44.         //  Set JAGG settings for this class
  45.         //
  46.         jaggSQL = new JDPJagg(user.jaggPath);
  47.         jaggSQL.setNULL("space");
  48. >996        jaggSQL.setMRW("<maxRows>");
  49. >998        jaggSQL.setDSN("<datasource>");
  50. >999        jaggSQL.setCSTR("<connectstr>");
  51.  
  52.         setLayout(new BorderLayout());
  53.         setFont(user.plainFont);
  54.          popuppanel = new JDPPopupMessage(user,targetPanel);
  55.         targetPanel.add(popuppanel);
  56.  
  57.         Panel mainPanel = new Panel();
  58.         mainPanel.setLayout(new BorderLayout());
  59.         Panel centerMainPanel = new Panel();
  60.         centerMainPanel.setLayout(new BorderLayout());
  61.  
  62.         //
  63.         //  Create a new instance of a Grid
  64.         //
  65.         tableContents = new JDPTextGrid(user);
  66.         mainPanel.add("Center",tableContents);
  67.         centerMainPanel.add("Center",mainPanel);
  68.         //
  69.         //  Add buttons to the bottom of the panel
  70.         //
  71.         if (moduleParameter.compareTo("Inquiry") == 0) {
  72.         } else {
  73. >015            String buttons[] = {<"   Apply   ","Reset","New","Copy","Remove">};
  74. >047            int icons[] = {<>};
  75.             JDPButtons btns = new JDPButtons(user, buttons, icons, JDPButtons.HORIZONTAL);
  76.             centerMainPanel.add("South",btns);
  77. >046            popuppanel.addComponent(btns.button[<0>],"<>","<>");
  78.         }
  79.         
  80.         //
  81.         //  Define parameters for JDPWhereClause
  82.         //
  83. >016        String[] pchooseFrom = new String[<7>];
  84. >017        pchooseFrom[<0>] = "<Account Name>";
  85.  
  86. >018        String[] pactualchooseFrom = new String[<7>];
  87. >019        pactualchooseFrom[<0>] = "<username>";
  88.  
  89. >024        boolean[] constantIsString = new boolean[<7>];
  90. >025        constantIsString[<0>] = <true>;
  91.  
  92. >026        int[] constantLength = new int[<7>];
  93. >027        constantLength[<0>] = <20>;
  94.  
  95.         loadMatchUsing();
  96.         //
  97.         //  Add JDPWhereClause search panel
  98.         //
  99.         if (pchooseFrom.length > 0) {
  100. >028            jdpWhereClause = new JDPWhereClause(user, targetPanel, "<UserBill>", false, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  101.                                                 pmatchUsing, pactualmatchUsing, null, null,
  102.                                                 constantLength, constantIsString);
  103.             centerMainPanel.add("North",jdpWhereClause);
  104.         }
  105.  
  106. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",centerMainPanel,"North"));
  107.         loadGrid();
  108.  
  109.         //
  110.         //  Add the handle to this panel to the global vector so other panels can
  111.         //  access this one
  112.         //
  113.         user.gParm.addElement(this);
  114.     }
  115.  
  116.     //
  117.     //  Handle screen events
  118.     //
  119.     public boolean handleEvent(Event e) {
  120.  
  121.         switch (e.id) {
  122.         case Event.ACTION_EVENT:
  123.             if (e.target instanceof Button) {
  124.                 String choice = (String)e.arg;
  125.                 if (choice.trim().compareTo("Apply") == 0) {
  126.                     if (checkFields()) {
  127.                         checkRows();
  128.                     }
  129.                     return true;
  130.                 }
  131.                 if (choice.trim().compareTo("Reset") == 0) {
  132.                     loadGrid();
  133.                     return true;
  134.                 }
  135.                 if (choice.trim().compareTo("Remove") == 0) {
  136. >054                    String removeMsg = "<>";
  137.                     if (removeMsg.equals("") || user.mainmsg.getStatusMsg().equals(removeMsg)) {
  138.                         deleteRequested = true;
  139.                         checkRows();
  140.                     } else {
  141.                         user.mainmsg.setStatusMsg(removeMsg,15);
  142.                     }
  143.                     return true;
  144.                 }
  145.                 if (choice.trim().compareTo("Search") == 0) {
  146.                     newSearch();
  147.                     return true;
  148.                 }
  149.                 return false;
  150.             }
  151.             if (e.target instanceof Choice) {
  152.                 return true;
  153.             }
  154.             if (e.target instanceof TextField) {
  155.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  156.                     newSearch();
  157.                     return true;
  158.                 }
  159.                 checkFields();
  160.                 return true;
  161.             }
  162.             return false;
  163.  
  164.         case Event.WINDOW_EXPOSE:
  165.             if (e.target instanceof JDPTabSelectPanel) {
  166.                 //
  167.                 //  This is where you place code to get executed when this panel is
  168.                 //  reactivated from the tab menu
  169.                 //
  170.                 return true;
  171.             }
  172.             return false;
  173.  
  174.           case Event.MOUSE_MOVE:
  175.          case Event.MOUSE_ENTER:
  176.          case Event.MOUSE_EXIT:
  177.             popuppanel.postEvent(e);
  178.             return false;
  179.  
  180.         default:
  181.             return false;
  182.  
  183.         }
  184.     }
  185.  
  186.     //
  187.     //  Retrieve the handle to another panel so as to be able to interact with it
  188.     //
  189.     public void retrieveHandle() {
  190.  
  191.         for (int ix=0; ix<user.gParm.size(); ix++) {
  192.             //
  193.             //  Activate the next four lines of code to retrieve the handle to another 
  194.             //  Panel within your JDP system. Of course you should declare the variable 
  195.             //  at the top of this source instead of within this method so you can 
  196.             //  access it from all the methods within this class. You only need to 
  197.             //  substitute DemoClass with the name ouf your class. You should call this 
  198.             //  method from somewhere else in this class. To access a variable from 
  199.             //  your resulting class use:
  200.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  201.             //
  202. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  203. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  204. //                return;
  205. //            }
  206.         }
  207.     }
  208.  
  209.     //
  210.     //  The search button was pressed so rerun the query with the new search criteria
  211.     //
  212.     public void newSearch() {
  213.  
  214.         loadGrid();
  215.     }
  216.  
  217.     //
  218.     //  The check each rows that has changed and issue an update to the database
  219.     //
  220.     public void checkRows() {
  221.  
  222.         int changedCount = 0;
  223.         int insertedCount = 0;
  224.         int deletedCount = 0;
  225.         int cCount = 1;
  226.         int iCount = 1;
  227.         
  228.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  229.             if (deleteRequested && tableContents.rowSelected[ix]) {
  230.                 deletedCount++;
  231.             } else
  232.             if (tableContents.rowChanged[ix]) {
  233.                 if (ix >= totalRows) {
  234.                     insertedCount++;
  235.                 } else {
  236.                     changedCount++;
  237.                 }
  238.             }
  239.         }
  240.         for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  241.             if (deleteRequested && tableContents.rowSelected[ix]) {
  242.                 user.mainmsg.setStatusMsg("Deleting row " + Integer.toString(iCount++) + " of " + Integer.toString(deletedCount) + "...", 0);
  243.                 saveData(ix);
  244.             } else
  245.             if (tableContents.rowChanged[ix]) {
  246.                 insertRequested = false;
  247.                 if (ix >= totalRows) {
  248.                     insertRequested = true;
  249.                     user.mainmsg.setStatusMsg("Inserting row " + Integer.toString(iCount++) + " of " + Integer.toString(insertedCount) + "...", 0);
  250.                 } else {
  251.                     user.mainmsg.setStatusMsg("Updating row " + Integer.toString(cCount++) + " of " + Integer.toString(changedCount) + "...", 0);
  252.                 }
  253.                 saveData(ix);
  254.                 insertRequested = false;
  255.                 tableContents.rowChanged[ix] = false;
  256.             }
  257.         }
  258.         if ((deletedCount > 0) || (insertedCount > 0)) {
  259.             loadGrid();
  260.         }
  261.         deleteRequested = false;
  262.     }
  263.  
  264.     //
  265.     //  Save the selected item
  266.     //
  267.     public boolean saveData(int tableRow) {
  268.  
  269.         int recCount = 0;
  270.         Vector results = new Vector();
  271.         String sep = jaggSQL.getSEP();
  272.         String SQL = "";
  273.  
  274.         if (insertRequested) {
  275. >121            SQL = <INSERT INTO >;
  276.         } else {
  277.             if (deleteRequested) {
  278. >122                SQL = <DELETE FROM >;
  279.             } else {
  280. >123                SQL = <UPDATE >;
  281.             }
  282.         }
  283.  
  284.         recCount = jaggSQL.execSQL(SQL, results);
  285.  
  286.         if (user.DEBUG) System.out.println("saveData CNT: "+Integer.toString(recCount));
  287.  
  288.         if(recCount == -1) {
  289.             user.u.setSqlMessage(jaggSQL,SQL);
  290.             return false;
  291.         }
  292.         if(recCount == 1) {
  293.             if (insertRequested) {
  294.                 user.mainmsg.setStatusMsg("Record successfully added.",3);
  295.             } else 
  296.             if (deleteRequested) {
  297.                 user.mainmsg.setStatusMsg("Record successfully removed.",3);
  298.             } else {
  299.                 user.mainmsg.setStatusMsg("Record successfully updated.",3);
  300.             }
  301.         } else {
  302.             user.u.setSqlMessage(jaggSQL,SQL);
  303.         }
  304.         return true;
  305.  
  306.     }
  307.  
  308.     //
  309.     //  Load the grid with the specified parameters and selected data
  310.     //
  311.     public void loadGrid() {
  312.  
  313.         StringTokenizer stok;
  314.         int recCount = 0;
  315.         Vector results = new Vector();
  316.         String sep = jaggSQL.getSEP();
  317.         int actualRows = 0;
  318.         String row;
  319.  
  320.         Vector columns = new Vector();
  321.         Vector indexes = new Vector();
  322.  
  323. >100        String SQL = <SELECT>;
  324.  
  325.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  326.  
  327.         recCount = jaggSQL.execSQL(SQL, results);
  328.  
  329.         if(recCount == -1) {
  330.             user.u.setSqlMessage(jaggSQL,SQL);
  331.             return;
  332.         }
  333.  
  334.         //
  335.         //  Initialise result arrays
  336.         //
  337.         totalRows = jaggSQL.getRowCount();
  338.         actualRows = jaggSQL.getRowCount()+20;
  339.         tableContents.currentText = new String[columnCount][actualRows];
  340.         //
  341.         //  If we haven't already initialise the grid settings
  342.         //
  343.         if (columnCount != prevColumnCount) {
  344.             prevColumnCount = columnCount;
  345.             setGridSettings();
  346.         }
  347.         tableContents.cellChanged = null;
  348.         tableContents.rowChanged = null;
  349.         tableContents.columnSelected = null;
  350. >120        keyCount = <keycount>;
  351.         rowKey = new String[actualRows][keyCount];
  352.         
  353.         //
  354.         //  Load key array and grid array
  355.         //
  356.         String tempText;
  357.         for (int ix=0; ix<actualRows-20; ix++) {
  358.             row = (String)results.elementAt(ix);
  359.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  360.                 stok = new StringTokenizer(row);
  361.                 for (int iy=0; iy<keyCount; iy++) {
  362.                     rowKey[ix][iy] = stok.nextToken(sep).trim();
  363.                 }
  364.                 for (int iy=0; iy<columnCount; iy++) {
  365.                     tempText = stok.nextToken(sep).trim();
  366.                     tableContents.currentText[iy][ix] = tempText;
  367. >053                    if ((iy == <1>) && (value<field>.indexOf(tempText) >= 0)) tableContents.currentText[iy][ix] = tableContents.pullDownList[<1>][0].getItem(value<field>.indexOf(tempText));
  368.                 }
  369.             }
  370.         }
  371.  
  372.         tableContents.newTable();
  373.  
  374.         //
  375.         //  Clear status message
  376.         //
  377.         user.mainmsg.clearStatusMsg();
  378.     }
  379.  
  380.     //
  381.     //  Load the grid with the blank rows to allow data entry
  382.     //
  383.     public void loadEmptyGrid() {
  384.  
  385.         tableContents.currentText = new String[columnCount][50];
  386.         tableContents.cellChanged = null;
  387.         tableContents.rowChanged = null;
  388.         tableContents.columnSelected = null;
  389.         rowKey = new String[50][keyCount];
  390.         tableContents.newTable();
  391.         totalRows = 0;
  392.     }
  393.  
  394.     //
  395.     //  Set up the parameters for this grid
  396.     //
  397.     public void setGridSettings() {
  398.  
  399.         tableContents.columnHeader = new String[columnCount];
  400.         tableContents.columnHeaderStyle = new int[columnCount];
  401.         tableContents.columnStyle = new int[columnCount];
  402.         tableContents.columnHeaderColor = new Color[columnCount];
  403.         tableContents.columnColor = new Color[columnCount];
  404.         tableContents.columnBGColor = new Color[columnCount];
  405.         tableContents.columnProtected = new boolean[columnCount];
  406.         tableContents.columnWidth = new int[columnCount];
  407.         tableContents.rightJustify = new boolean[columnCount];
  408.         tableContents.rowHeader = null;
  409.         tableContents.columnHeight = null;
  410.         for (int ix=0; ix<columnCount; ix++) {
  411.             tableContents.columnHeaderStyle[ix] = Font.BOLD;
  412.             tableContents.columnStyle[ix] = Font.PLAIN;
  413.             tableContents.columnHeaderColor[ix] = Color.black;
  414.             tableContents.columnColor[ix] = Color.black;
  415.             tableContents.columnBGColor[ix] = Color.white;
  416.             tableContents.columnStyle[ix] = Font.PLAIN;
  417.         }
  418. >101        tableContents.columnHeader[<ix>] = "<>";
  419. >102        tableContents.columnHeaderStyle[<ix>] = <>;
  420. >103        tableContents.columnStyle[<ix>] = <>;
  421. >104        tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
  422. >105        tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
  423. >106        tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
  424. >107        tableContents.columnProtected[<ix>] = <>;
  425. >108        tableContents.columnWidth[<ix>] = <>;
  426. >109        tableContents.rightJustify[<ix>] = <>;
  427.  
  428.         loadChoices();
  429.     }
  430.  
  431.     //
  432.     //  Load the Search Layout pulldown choices
  433.     //
  434.     public void loadMatchUsing() {
  435.  
  436.         pmatchUsing = new Vector();
  437.         pactualmatchUsing = new Vector();
  438. >020        pmatchUsing.addElement(new Vector());
  439. >022        pactualmatchUsing.addElement(new Vector());
  440. >021        ((Vector)pmatchUsing.elementAt(<0>)).addElement("<Begins with>");
  441. >023        ((Vector)pactualmatchUsing.elementAt(<0>)).addElement("< like >");
  442.  
  443.     }
  444.  
  445.     //
  446.     //  Load all of the Screen Choices
  447.     //
  448.     public void loadChoices() {
  449.  
  450.         tableContents.isPullDownCol = new boolean[columnCount];
  451.         tableContents.pullDownList = new List[columnCount][1];
  452. >049        tableContents.isPullDownCol[<1>] = true;
  453. >049        tableContents.pullDownList[<1>][0] = new List();
  454. >050
  455. >051        new JDPLoadChoice(user,jaggSQL,tableContents.pullDownList[<1>][0],"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",value<columnname>);
  456.     }
  457.  
  458.     //
  459.     //  Perform component validations
  460.     //
  461.     public boolean checkFields() {
  462.  
  463.         return true;
  464.  
  465.     }
  466.  
  467.  
  468. }
  469.